<template>
    <div style="padding: 10px;">
        <p>问题描述：</p>
        <p>1. 展开Tree的所有层级，然后点击按钮</p>
        <p>2. 方法会去掉key=1_1_1的节点，此时控制台就会报错了</p>
        <a-directory-tree :showIcon="false" :tree-data="treeData" v-model:expandedKeys="expandedKeys"/>
        <a-button @click="reloadTreeData">我已展开Tree所有层级，验证BUG</a-button>
    </div>
</template>

<script>
    import {toRefs, ref, reactive, onMounted, watch} from 'vue';

    export default {
        setup() {
            let treeData = ref(
                [
                    {
                        "key": "main",
                        "title": "展开我",
                        "children": [
                            {
                                "title": "再把我展开",
                                "key": 1,
                                "children": [
                                    {
                                        "title": "我是第一个",
                                        "key": "1_1_1",
                                        "isLeaf": true
                                    },
                                    {
                                        "title": "我是第二个",
                                        "key": "1_2_1",
                                        "isLeaf": true
                                    }
                                ]
                            }
                        ]
                    }
                ]
            );
            let expandedKeys = ref([]);
            const reloadTreeData = () => {
                expandedKeys.value = ['main'];
                treeData.value = [
                    {
                        "key": "main",
                        "title": "展开我",
                        "children": [
                            {
                                "title": "你展开不了我了",
                                "key": 1,
                                "children": [
                                    {
                                        "title": "我是第二个",
                                        "key": "1_2_1",
                                        "isLeaf": true
                                    }
                                ]
                            }
                        ]
                    }
                ];
            };
            return {
                expandedKeys,
                treeData,
                reloadTreeData,
            };
        },
    };
</script>
